import Reqwest from '../../utils/Reqwest';
import {AdPositionBean} from './AdPositionBean';
import {base, assign, redirect}  from '../base/Base';
import {ResponseDto} from '../base/BaseDTO';
declare let GLOBAL:any;

export class AdPositionService {
    path = `${GLOBAL.baseApiUrl}/adConfigPosition/api`;

    searchAdPosition(params?: any, options = {}): Promise<any> {
        return new Reqwest(assign({
            url: `${this.path}/list.jhtml`,
            method: 'get',
            type: 'json',
            contentType: 'application/json; charset=UTF-8',
            data: params || {},
            headers: {
                'X-CSRF-TOKEN': base._csrf
            }
        }, options)).catch(redirect);
    }

    getAdPosition(params: {
        id: number
    }, options = {}): Promise<ResponseDto<AdPositionBean<any>>> {
        return new Reqwest(assign({
            url: `${this.path}/view.jhtml`,
            method: 'get',
            type: 'json',
            contentType: 'application/json; charset=UTF-8',
            data: params || {},
            headers: {
                'X-CSRF-TOKEN': base._csrf
            }
        }, options)).catch(redirect);
    }

    editAdPosition(params: AdPositionBean<any>, options = {}): Promise<ResponseDto<any>> {
        return new Reqwest(assign({
            url: `${this.path}/edit.jhtml`,
            method: 'post',
            type: 'json',
            contentType: 'application/json; charset=UTF-8',
            data: JSON.stringify(params) || {},
            headers: {
                'X-CSRF-TOKEN': base._csrf
            }
        }, options)).catch(redirect);
    }

    addAdPosition(params: AdPositionBean<any>, options = {}): Promise<ResponseDto<any>> {
        return new Reqwest(assign({
            url: `${this.path}/add.jhtml`,
            method: 'post',
            type: 'json',
            contentType: 'application/json; charset=UTF-8',
            data: JSON.stringify(params) || {},
            headers: {
                'X-CSRF-TOKEN': base._csrf
            }
        }, options)).catch(redirect);
    }

    deleteAdPosition(params?: {
        id: number
    }, options = {}): Promise<ResponseDto<any>> {
        return new Reqwest(assign({
            url: `${this.path}/delete.jhtml`,
            method: 'get',
            type: 'json',
            contentType: 'application/json; charset=UTF-8',
            data: params || {},
            headers: {
                'X-CSRF-TOKEN': base._csrf
            }
        }, options)).catch(redirect);
    }
}